$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {

    var mstform = $NG.getCmpApi('p_form_gzxmxx_m');
    var dgrid = $NG.getCmpApi('grid');

    if (page.oType == "add") {
        // 获取当前日期（年月日格式）
        const now = new Date();
        const year = now.getFullYear();
        const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份补零
        const day = String(now.getDate()).padStart(2, '0');        // 日期补零
        const currentDate = `${year}-${month}-${day}`;  // 格式：YYYY-MM-DD

        // 获取目标字段（替换"u_your_date_field"为实际字段名）
        const dateField = mstform.getItem('ng_insert_dt');

        // 设置字段值
        if (dateField) {
            dateField.setValue(currentDate);
        } else {
            console.warn('日期字段未找到，请检查字段名');
        }
    }
    // 根据数组查找元素的位置
    function getHTMLDOM(path, arr) {
        let dom = document.querySelector(path)
        arr.forEach(item => {
            dom = dom.childNodes[item]
        })
        return dom
    }

    // 设置行颜色
    function setRowsColor() {
        try {
            const dom = getHTMLDOM("#grid", [0, 0, 0, 1, 0, 0, 0])
            let _catch = 0
            const configColor = {
                1: "#000000ff",
                2: "#ead200ff",
                3: "#ead200ff",
                4: "#6ecf00ff",
                5: "#6ecf00ff",
                init: 'rgba(0, 0, 0, 1)'
            }
            // 循环行
            if (dom.childNodes) {
                if (_catch != dom.childNodes.length) {
                    dom.childNodes.forEach(item => {
                        if (item.childNodes && item.childNodes.length != 0) {
                            const doms = item.childNodes
                            let color = 'init'
                            // 初次循环判断用什么颜色
                            doms.forEach(el => {
                                const key = el.getAttribute("data-key")
                                if (key == 'u_gzjb') {
                                    const rowDom = el.childNodes
                                    if (rowDom.length != 0) {
                                        const content = rowDom[0].textContent.trim()
                                        switch (content.length) {
                                            case 1:
                                                color = '1'
                                                break;
                                            case 2:
                                            case 3:
                                                color = '3'
                                                break
                                            case 4:
                                            case 5:
                                                color = '4'
                                                break
                                        }
                                        // 设置重要等级字体颜色
                                        rowDom[0].style.color = configColor[color]
                                    }
                                }
                            })
                            // 循环列（设置行颜色）
                            // doms.forEach((el, index) => {
                            //     if (index == 0) {
                            //         const temp = el.childNodes[0]
                            //         if (temp) {
                            //             temp.style.background = configColor[color]
                            //         }
                            //     }

                            //     el.style.background = configColor[color]
                            // })
                            _catch = dom.childNodes.length
                        } else {

                        }

                    })
                }

            }
        } catch (err) {
            console.error(`改变行颜色模块报错`, err);
        }
    }
    // 判断是不是列表
    if (page.isList) {
        // 初始化执行一次
        setTimeout(() => {
            setRowsColor()
        }, 200)
        // 定时执行一次
        setInterval(() => {
            setRowsColor()
        }, 1000)

    }
    $NG.updateUI((updater, state) => {
        updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
            onBeforeOpen: async () => {
                var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_ywlb').getValue();

                if (!phid_pc) {
                    $NG.alert("请先选择业务类别");
                    return false;
                } else {
                    return true;
                }
            },
        });
    });
    $NG.updateUI((updater, state) => {
        updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
            onBeforeOpen: async () => {
                var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_sccyllb').getValue();

                if (!phid_pc) {
                    $NG.alert("请先选择市场产业链类别");
                    return false;
                } else {
                    return true;
                }
            },
        });
    });

    // 创建跟踪级别弹框
    tranceLevelWindow()
    // 重写确认方法
    window.traceLeveConfirmModal = (value) => {
        let rows = dgrid.getSelectedData()
        if (rows.length == 0) {
            $NG.alert("请选中一条数据！")
            return
        }
        rows = rows[0]
        if (!value) return
        const level = ( 6- Number(value) || 0)
        let zd = '02'
        if (level >= 4) {
            zd = '01'
        }
        console.log(`ad`,zd,level);
        $NG.execServer("UPDATE", { tableName: 'p_form_gzxmxx_m', valueSql: `u_sfzdgzxm = '${zd}', u_gzjb = '${value}'`, filterSql: `phid = '${rows.phid}'` }, (res) => {
            if (res.status == 'success') {
                $NG.alert("调整成功！")
                $NG.refresh()
            } else {
                $NG.alert("调整失败！")

            }
            window.traceLeveCloseModal()
        })

    }
    // 级别调整
    useClick(() => {
        window.traceLeveOpenModal()
    }, "u_jbtz")

    useClick(function ({ toolbar }) {
        let rows = dgrid.getSelectedData()

        if (rows.length < 1) {
            $NG.alert('请先选择数据')
            return
        }
        if (!rows.every(item => item.u_sfzdgzxm == '01')) {
            $NG.alert('只能汇报重点项目！');
            return;
        }
        let a = rows[0].u_jhzbjcze
        let b = rows[0].u_jbys
        let u_mqjzqk = rows[0].u_mqjzqk ///目前进展情况
        let u_jbys = rows[0].u_jbys///竞标优势
        const overlay = document.createElement('div');
        overlay.style = `
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 9999;
    `;

        // 创建弹窗容器
        const modal = document.createElement('div');
        modal.style = `
        background: white;
        padding: 24px;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        width: 500px;
        animation: slideIn 0.3s ease;
    `;

        // 弹窗内容 - 已修改为可编辑文本框
        modal.innerHTML = `
        <h3 style="margin:0 0 16px; color: #333; font-size: 18px;">项目信息确认</h3>
        
        <div style="margin-bottom: 16px;">
            <label style="display: block; margin-bottom: 8px; color: #666;">目前进展情况：</label>
            <textarea 
                id="currentProgress" 
                style="
                    width: 100%;
                    height: 80px;
                    padding: 8px;
                    border: 1px solid #ddd;
                    border-radius: 4px;
                    margin-bottom: 16px;
                    resize: vertical;
                    background-color: #fff; /* 改为白色背景 */
                "
            ></textarea> <!-- 移除 readonly 属性 -->
        </div>
        
        <div style="margin-bottom: 16px;">
            <label style="display: block; margin-bottom: 8px; color: #666;">竞争优势：</label>
            <textarea 
                id="competitiveAdvantage" 
                style="
                    width: 100%;
                    height: 80px;
                    padding: 8px;
                    border: 1px solid #ddd; 
                    border-radius: 4px;
                    margin-bottom: 16px;
                    resize: vertical;
                    background-color: #fff; /* 改为白色背景 -->
                "
            ></textarea> <!-- 移除 readonly 属性 -->
        </div>
        
        <div style="display: flex; justify-content: flex-end; gap: 8px;">
            <button id="cancelBtn" style="
                padding: 8px 16px;
                border: 1px solid #ddd;
                border-radius: 4px;
                background: white;
                cursor: pointer;
            ">取消</button>
            <button id="confirmBtn" style="
                padding: 8px 16px;
                border: none;
                border-radius: 4px;
                background: #1890ff;
                color: white;
                cursor: pointer;
            ">确认汇报</button>
        </div>
    `;

        // 添加到页面
        overlay.appendChild(modal);
        document.body.appendChild(overlay);

        // 设置初始值
        document.getElementById('currentProgress').value = u_mqjzqk || '';
        document.getElementById('competitiveAdvantage').value = u_jbys || '';

        // 添加动画
        const style = document.createElement('style');
        style.innerHTML = `
        @keyframes slideIn {
          from { transform: translateY(-20px); opacity: 0; }
          to { transform: translateY(0); opacity: 1; }
        }
    `;
        document.head.appendChild(style);

        // 绑定事件
        const confirmBtn = modal.querySelector('#confirmBtn');
        const cancelBtn = modal.querySelector('#cancelBtn');

        // 确认汇报逻辑
        confirmBtn.onclick = () => {
            let rows = dgrid.getSelectedData();

            // 获取用户编辑后的内容
            const updatedProgress = document.getElementById('currentProgress').value;
            const updatedAdvantage = document.getElementById('competitiveAdvantage').value;
            const promises = rows.map(row => {
                return new Promise((resolve, reject) => {

                    // 创建更新SQL - 包含用户编辑的内容
                    const u_jbys = updatedAdvantage
                    const u_mqjzqk = updatedProgress
                    const phid = row.phid
                    // $NG.execServer("updateGjProject", { u_jbys, u_mqjzqk, phid }, (res) => {
                    //     if (res.status == 'success') {
                    //         $NG.execServer("updateIshb", { phid: row.phid }, (res) => {
                    //             if (res.status == 'success') {
                    //                 resolve()

                    //             } else {
                    //                 reject()

                    //             }

                    //         });
                    //     } else {
                    //         reject()
                    //     }
                    // })
                    //% 根据phid插入明细
                    $NG.execServer("insertTraceProjectDetail", { u_jbys, u_mqjzqk, phid }, (res) => {
                        if (res.status == 'success') {
                            $NG.execServer("updateIshb", { phid: row.phid }, (res) => {
                                if (res.status == 'success') {
                                    resolve()

                                } else {
                                    reject()

                                }

                            });
                        } else {
                            reject()
                        }
                    })
                });
            });

            Promise.all(promises)
                .then(() => {
                    $NG.alert('汇报成功！');
                    document.body.removeChild(overlay);
                    document.head.removeChild(style);
                })
                .catch(() => {
                    $NG.alert('部分数据修改失败，请检查日志');
                });
        };

        // 取消逻辑
        const closeModal = () => {
            document.body.removeChild(overlay);
            document.head.removeChild(style);
        };

        cancelBtn.onclick = closeModal;
    }, 'u_hb');

    useValuesChange(({ args }) => {
        $NG.updateUI((updater, state) => {
            updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_ywlb').getValue();

                    if (!phid_pc) {
                        $NG.alert("请先选择业务类别");
                        return false;
                    } else {
                        return true;
                    }
                },
            });
        });
        if (mstform.getItem('u_ywlb').getValue() == 6870000000000110) {
            // mstform.getItem('u_sccyllb').setValue('')

            $NG.updateUI((updater, value) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
                    required: true,
                    hidden: false,
                    // disable: true,
                });
            });
            // $NG.updateUI((updater) => {
            //     updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
            //         disabled: false,
            //         clientSqlFilter: `phid = 6870000000000011`, //过滤条件
            //     });
            // });
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
                    disabled: false,
                    clientSqlFilter: `c_descript = '传统业务'`, //过滤条件
                });
            });
        } else if (mstform.getItem('u_ywlb').getValue() == 6870000000000111) {
            mstform.getItem('u_sccyllb').setValue('')
            $NG.updateUI((updater, value) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
                    required: true,
                    hidden: false,
                    // disable: true,
                });
            });
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
                    disabled: false,
                    clientSqlFilter: `c_descript = '非传统业务'`, //过滤条件
                });
            });

        } else if (mstform.getItem('u_ywlb').getValue() == 6870000000000112) {
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
                    disabled: false,
                    clientSqlFilter: `c_descript = '国际项目'`, //过滤条件
                });
            });
            $NG.updateState((updater) => {
                updater.data.p_form_gzxmxx_m.setProps({
                    u_sccyllb: {
                        //事业部or组织
                        value: 6870000000000085,
                        label: '国际项目',
                    },

                });
            });
            $NG.updateUI((updater, value) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
                    required: false,
                    hidden: true,
                    // disable: true,
                });
            });

        } else {
            let newlb = mstform.getItem('u_ywlb').getText()
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
                    disabled: false,
                    clientSqlFilter: `c_descript = '${newlb}'`, //过滤条件
                });
            });
        }


        setKeyCityHidden()
    }, "p_form_gzxmxx_m.u_ywlb");

    // 省份帮助
    useValuesChange(()=>{
        getRegin()
    },"p_form_gzxmxx_m.u_xmszd")

    useValuesChange(() => {
        const num = (6 - Number(mstform.getItem("u_gzjb").getValue()) || 0)
        if (num && num >= 4) {
            mstform.getItem("u_sfzdgzxm").setValue('01')
        } else {
            mstform.getItem("u_sfzdgzxm").setValue('02')
        }
    }, "p_form_gzxmxx_m.u_gzjb")
    useValuesChange(({ args }) => {
        $NG.updateUI((updater, state) => {
            updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_sccyllb').getValue();

                    if (!phid_pc) {
                        $NG.alert("请先选择市场产业链类别");
                        return false;
                    } else {
                        return true;
                    }
                },
            });
        });
        let newlb = mstform.getItem('u_sccyllb').getText()
        $NG.updateUI((updater) => {
            updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
                disabled: false,
                clientSqlFilter: `c_descript = '${newlb}'`, //过滤条件
            });
        });
        if (mstform.getItem('u_sccyllb').getValue() == 6870000000000011) {

        }
        else if (mstform.getItem('u_sccyllb').getValue() == 6870000000000081) {
            $NG.updateState((updater) => {
                updater.data.p_form_gzxmxx_m.setProps({
                    u_hylb: {
                        //事业部or组织
                        value: 6870000000000009,
                        label: '铁路工程',
                    },

                });
            });

        }
        else if (mstform.getItem('u_sccyllb').getValue() == 6870000000000082) {
            $NG.updateState((updater) => {
                updater.data.p_form_gzxmxx_m.setProps({
                    u_hylb: {
                        //事业部or组织
                        value: 6870000000000086,
                        label: '水务工程',
                    },

                });
            });

        }
        else if (mstform.getItem('u_sccyllb').getValue() == 6870000000000083) {
            $NG.updateState((updater) => {
                updater.data.p_form_gzxmxx_m.setProps({
                    u_hylb: {
                        //事业部or组织
                        value: 6870000000000091,
                        label: '储贷',
                    },

                });
            });

        }
        else if (mstform.getItem('u_sccyllb').getValue() == 6870000000000084) {
            $NG.updateState((updater) => {
                updater.data.p_form_gzxmxx_m.setProps({
                    u_hylb: {
                        //事业部or组织
                        value: 6870000000000101,
                        label: '软件与信息技术服务',
                    },

                });
            });

        }

    }, "p_form_gzxmxx_m.u_sccyllb");
    zdyc()
    function zdyc() {
        var mstform = $NG.getCmpApi('p_form_gzxmxx_m');
        if (mstform.getItem('u_xmms').getValue() == 6870000000000108) {
            $NG.updateUI((updater) => {
                const fields = ["u_syms", "u_gkgx", "u_jhzbjcze", 'u_tbhzdw', 'u_zbsj'];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: false, //隐藏
                        required: true, //必输
                        // disabled: true, //只读
                    });
                });
            });
            $NG.updateUI((updater) => {
                const fields = ["u_zbsj"];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: false, //隐藏
                        // required: true, //必输
                        // disabled: true, //只读
                    });
                });
            });
        } else {
            $NG.updateUI((updater) => {
                const fields = ["u_syms", "u_gkgx", "u_jhzbjcze", 'u_tbhzdw', 'u_zbsj'];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: true, //隐藏
                        required: false, //必输
                        // disabled: true, //只读
                    });
                });
            });
            $NG.updateUI((updater) => {
                const fields = ["u_zbsj"];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: true, //隐藏
                        // required: true, //必输
                        // disabled: true, //只读
                    });
                });
            });
        }
        if (mstform.getItem('u_ywlb').getValue() == 6870000000000110) {
            $NG.updateUI((updater, value) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
                    required: true,
                    hidden: false,
                    // disable: true,
                });
            });
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
                    disabled: false,
                    clientSqlFilter: `phid = 6870000000000011`, //过滤条件
                });
            });
        } else if (mstform.getItem('u_ywlb').getValue() == 6870000000000111) {
            $NG.updateUI((updater, value) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
                    required: true,
                    hidden: false,
                    // disable: true,
                });
            });
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
                    disabled: false,
                    clientSqlFilter: `phid = 6870000000000081 or phid = 6870000000000082 or phid = 6870000000000083 or phid = 6870000000000084 `, //过滤条件
                });
            });

        } else if (mstform.getItem('u_ywlb').getValue() == 6870000000000112) {
            $NG.updateUI((updater) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_sccyllb.setProps({
                    disabled: true,
                    clientSqlFilter: `phid = 6870000000000085 `, //过滤条件
                });
            });
            $NG.updateState((updater) => {
                updater.data.p_form_gzxmxx_m.setProps({
                    u_sccyllb: {
                        //事业部or组织
                        value: 6870000000000085,
                        label: '国际项目',
                    },

                });
            });
            $NG.updateUI((updater, value) => {
                updater.fieldSetForm.p_form_gzxmxx_m.u_hylb.setProps({
                    required: false,
                    hidden: true,
                    // disable: true,
                });
            });

        }
        if (mstform.getItem('u_hylb').getValue() == 6870000000000089) {
            $NG.updateUI((updater) => {
                const fields = ["u_ejhylb"];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: false, //隐藏
                        required: true, //必输
                        // disabled: true, //只读
                    });
                });
            });
        } else {
            $NG.updateUI((updater) => {
                const fields = ["u_ejhylb"];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: true, //隐藏
                        required: false, //必输
                        // disabled: true, //只读
                    });
                });
            });
        }
    }
    useValuesChange(({ args }) => {
        if (mstform.getItem('u_xmms').getValue() == 6870000000000108) {
            $NG.updateUI((updater) => {
                const fields = ["u_syms", "u_gkgx", "u_jhzbjcze", 'u_tbhzdw', 'u_zbsj'];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: false, //隐藏
                        required: true, //必输
                        // disabled: true, //只读
                    });
                });
            });
            $NG.updateUI((updater) => {
                const fields = ["u_zbsj"];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: false, //隐藏
                        // required: true, //必输
                        // disabled: true, //只读
                    });
                });
            });
        } else {
            $NG.updateUI((updater) => {
                const fields = ["u_syms", "u_gkgx", "u_jhzbjcze", 'u_tbhzdw', 'u_zbsj'];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: true, //隐藏
                        required: false, //必输
                        // disabled: true, //只读
                    });
                });
            });
            $NG.updateUI((updater) => {
                const fields = ["u_zbsj"];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: true, //隐藏
                        // required: true, //必输
                        // disabled: true, //只读
                    });
                });
            });
        }

    }, "p_form_gzxmxx_m.u_xmms");
    useValuesChange(({ args }) => {
        $NG.updateUI((updater, state) => {
            updater.fieldSetForm.p_form_gzxmxx_m.u_xmszs.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_xmszd').getValue();

                    if (!phid_pc) {
                        $NG.alert("请先选择省份");
                        return false;
                    } else {
                        return true;
                    }
                },
                ...({
                    clientSqlFilter: {
                        provinceno: mstform.getItem("u_xmszd").getValue()
                    }
                }),
            });
        });
    }, "p_form_gzxmxx_m.u_xmszd")
    $NG.updateUI((updater, state) => {
        updater.fieldSetForm.p_form_gzxmxx_m.u_xmszs.setProps({
            onBeforeOpen: async () => {
                var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_xmszd').getValue();

                if (!phid_pc) {
                    $NG.alert("请先选择省份");
                    return false;
                } else {
                    return true;
                }
            },
        });
    });
    useValuesChange(({ args }) => {
        $NG.updateUI((updater, state) => {
            updater.fieldSetForm.p_form_gzxmxx_m.u_xmszx.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_xmszs').getValue();
                    if (!phid_pc) {
                        $NG.alert("请先选择市");
                        return false;
                    } else {
                        return true;
                    }
                },
                ...({
                    clientSqlFilter: {
                        cityno: mstform.getItem("u_xmszs").getValue()
                    }
                }),
            });
        });
    }, "p_form_gzxmxx_m.u_xmszs")
    $NG.updateUI((updater, state) => {
        updater.fieldSetForm.p_form_gzxmxx_m.u_xmszx.setProps({
            onBeforeOpen: async () => {
                var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_xmszs').getValue();
                if (!phid_pc) {
                    $NG.alert("请先选择市");
                    return false;
                } else {
                    return true;
                }
            },
        });
    });
    useValuesChange(({ args }) => {
        $NG.updateUI((updater, state) => {
            updater.fieldSetForm.p_form_gzxmxx_m.u_xmszx.setProps({
                onBeforeOpen: async () => {
                    var phid_pc = $NG.getCmpApi('p_form_gzxmxx_m').getItem('u_xmszs').getValue();
                    if (!phid_pc) {
                        $NG.alert("请先选择市");
                        return false;
                    } else {
                        return true;
                    }
                },
                ...({
                    clientSqlFilter: {
                        cityno: mstform.getItem("u_xmszs").getValue()
                    }
                }),
            });
        });
    }, "p_form_subcontractor_m.u_xmszx")
    useValuesChange(({ args }) => {
        if (mstform.getItem('u_hylb').getValue() == 6870000000000089) {
            $NG.updateUI((updater) => {
                const fields = ["u_ejhylb"];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: false, //隐藏
                        required: true, //必输
                        // disabled: true, //只读
                    });
                });
            });
        } else {
            $NG.updateUI((updater) => {
                const fields = ["u_ejhylb"];
                fields.forEach((field) => {
                    updater.fieldSetForm.p_form_gzxmxx_m[field].setProps({
                        hidden: true, //隐藏
                        required: false, //必输
                        // disabled: true, //只读
                    });
                });
            });
        }
    }, "p_form_gzxmxx_m.u_hylb");
    useValuesChange(({ args }) => {
        let u_Gzfzr = mstform.getItem('u_Gzfzr').getValue()
        $NG.execServer("searchPhone", { phid: u_Gzfzr }, (res) => {
            if (res.count == 0) return
            const data = JSON.parse(res.data)[0].extendObjects;
            mstform.getItem('u_gzfzrlxfs').setValue(data.mobile1)
            // $NG.updateState((updater) => {
            //     updater.formValue.setProps({
            //         PhidApplyPsn: {
            //             value: data.phid,
            //             label: data.bill_name
            //         }
            //     })
            // })
        });
    }, "p_form_gzxmxx_m.u_Gzfzr");
    useBeforeClick(async function ({ args }) {
        let bdmc = mstform.getItem('u_bdmc').getValue();
        // %@U2FsdGVkX1+gMSFRB2tjjJDpdhghIMJHwOe1ZES😀l/y😀LdplrSYFm6v3vfuM+😀cS&&0.0.5
        const u_tzys = mstform.getItem("u_tzys").getValue()
        if (u_tzys > 50 * 10000) {
            const lock = await $NG.confirm('投资估算超过50亿，请确定是否填写正确?')
            if (!lock) {
                return false
            }
        }
        if (page.oType == "add") {
            // 将异步操作包装成 Promise
            if (!bdmc) {
                $NG.alert("标段名称为空！")
                return
            }
            const checkResult = await new Promise((resolve) => {
                $NG.execServer("searchAllBdmc", { u_bdmc: bdmc }, (res) => {
                    if (res.count === 0) {
                        resolve(true); // 允许保存
                        return;
                    }

                    const data = JSON.parse(res.data)[0].extendObjects;

                    if (data.u_bdmc) {
                        $NG.alert('该标段名称已存在');
                        resolve(false); // 禁止保存
                    } else {
                        resolve(true); // 允许保存
                    }
                });
            });

            // 根据异步结果决定是否阻止保存
            if (!checkResult) {
                return false;
            }
        }

        // 默认允许保存
    }, "save");

    // 根据省份获取市场区域
    function getRegin(){
        const sf = mstform.getItem("u_xmszd").getValue()
        if(!sf) return 
        $NG.execServer("getRegionInfo",{sf},(res)=>{
            if(res.count == 0) return 
            const datas = JSON.parse(res.data)[0].extendObjects
            mstform.getItem("u_scqy").setValue({
                label:datas.c_name,
                value:datas.phid
            })
        })
    }

    // 关于国别和城市相关隐藏
    setKeyCityHidden()
    function setKeyCityHidden() {
        const configLock = {
            cityLock: true,
            gjLock: true
        }
        switch ((Number(mstform.getItem("u_ywlb").getValue()) || 0)) {
            case 6870000000000110:
                configLock.cityLock = false
                configLock.gjLock = true
                break;
            case 6870000000000111:
                configLock.cityLock = false
                configLock.gjLock = true
                break;
            case 6870000000000112:
                configLock.cityLock = true
                configLock.gjLock = false
                break;
            default:
                configLock.cityLock = true
                configLock.gjLock = true
        }
        const citys = ['u_xmszd', 'u_xmszs', 'u_xmszx', 'u_scfw']
        console.log(`lock`, configLock);
        citys.forEach(item => {
            $NG.updateUI(updater => {
                console.log(`updater`, updater);
                updater.fieldSetForm.p_form_gzxmxx_m[item].setProps({
                    hidden: configLock.cityLock
                })
            })
        })
        $NG.updateUI(updater => {
            console.log(`updater`, updater);
            updater.fieldSetForm.p_form_gzxmxx_m['u_szgb'].setProps({
                hidden: configLock.gjLock
            })
        })
    }
})

// 创建跟踪界别弹框
// %@U2FsdGVkX19😀igWaoiH0RajVKge8QS3IWC2DmL46feBXDEbdVTT+fiXJoIp9gXhlJ5NVhQiPcQu5vgP1tw1h1cyOHbf4l8dnpIzgMd3i4CM=&&0.0.5
function tranceLevelWindow() {
    const css = `body{font-family:"Microsoft YaHei",Arial,sans-serif;background:#f5f5f5}.gzjb_modal-overlay{position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.4);display:flex;justify-content:center;align-items:center;opacity:0;pointer-events:none;transition:opacity 0.3s ease;z-index:999}.gzjb_modal-overlay.gzjb_show{opacity:1;pointer-events:auto}.gzjb_modal{background:#fff;border-radius:12px;width:320px;padding:25px 20px;box-shadow:0 10px 25px rgba(0,0,0,0.2);transform:translateY(-20px);transition:transform 0.3s ease,opacity 0.3s ease;opacity:0}.gzjb_modal-overlay.gzjb_show .gzjb_modal{transform:translateY(0);opacity:1}.gzjb_modal h2{margin-top:0;color:#1890ff;font-size:20px;text-align:center}.gzjb_modal select{width:100%;padding:10px;margin:20px 0;border:1px solid #d9d9d9;border-radius:6px;appearance:none;outline:none;font-size:14px;transition:border-color 0.3s}.gzjb_modal select:focus{border-color:#1890ff;box-shadow:0 0 0 2px rgba(24,144,255,0.2)}.gzjb_modal-buttons{display:flex;justify-content:flex-end;gap:10px}.gzjb_modal-buttons button{padding:8px 16px;border:none;border-radius:6px;cursor:pointer;font-size:14px;transition:background 0.3s}.gzjb_confirm-btn{background-color:#1890ff;color:#fff}.gzjb_confirm-btn:hover{background-color:#40a9ff}.gzjb_cancel-btn{background-color:#f0f0f0;color:#333}.gzjb_cancel-btn:hover{background-color:#d9d9d9}`
    const html = `<div class="gzjb_modal-overlay" id="gzjb_modalOverlay"><div class="gzjb_modal"><h2>跟踪设置</h2><label for="gzjb_trackingLevel">跟踪级别:</label><select id="gzjb_trackingLevel"><option value="05">★</option><option value="04">★★</option><option value="03">★★★</option><option value="02">★★★★</option><option value="01">★★★★★</option></select><div class="gzjb_modal-buttons"><button class="gzjb_cancel-btn">取消</button><button class="gzjb_confirm-btn">确定</button></div></div></div>`
    const body = document.querySelector("body")
    const styleTag = document.createElement('style');
    styleTag.appendChild(document.createTextNode(css));
    document.head.appendChild(styleTag);
    body.insertAdjacentHTML('afterbegin', html)
    const gzjb_modalOverlay = document.getElementById('gzjb_modalOverlay'), ok = document.querySelector(".gzjb_confirm-btn"), no = document.querySelector(".gzjb_cancel-btn"); ok.addEventListener('click', () => { gzjb_confirmModal() }), no.addEventListener('click', () => { if (window.traceLeveNoModal) { window.traceLeveNoModal(level) } }); function traceLeveOpenModal() { gzjb_modalOverlay.classList.add('gzjb_show') } function traceLeveCloseModal() { gzjb_modalOverlay.classList.remove('gzjb_show') } window.traceLeveOpenModal = traceLeveOpenModal, window.traceLeveCloseModal = traceLeveCloseModal; function gzjb_confirmModal() { const level = document.getElementById('gzjb_trackingLevel').value; if (!window.traceLeveConfirmModal) { $NG.alert("window.traceLeveConfirmModal 未重写，运行失败！请联系管理员！"); return } window.traceLeveConfirmModal(level), traceLeveCloseModal() } gzjb_modalOverlay.addEventListener('click', e => { e.target === gzjb_modalOverlay && traceLeveCloseModal() });
}

